# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gnutls

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.3.1
pkgrel=1
pkgdesc="A library which provides a secure layer over a reliable transport layer (mingw-w64)"
arch=('any')
license=('GPL3' 'LGPL2.1')
url="http://www.gnutls.org/"
options=('!zipman')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
    "${MINGW_PACKAGE_PREFIX}-libtasn1"
    "${MINGW_PACKAGE_PREFIX}-libgcrypt"
    "${MINGW_PACKAGE_PREFIX}-gmp"
    "${MINGW_PACKAGE_PREFIX}-zlib"
    "${MINGW_PACKAGE_PREFIX}-nettle"
    "${MINGW_PACKAGE_PREFIX}-p11-kit"
    "${MINGW_PACKAGE_PREFIX}-libgnurx"
    "${MINGW_PACKAGE_PREFIX}-libgpg-error"
    #"${MINGW_PACKAGE_PREFIX}-unbound"
    )
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=(ftp://ftp.gnutls.org/gcrypt/gnutls/v3.3/${_realname}-${pkgver}.tar.xz{,.sig}
    0004-fix-gtkdoc.all.patch
    0005-fix-strtok-conflict.mingw.patch)
md5sums=('6bf7faa9d4996197e0e404e8c25016f8'
         'SKIP'
         '86cfab6e7c2ccfcfd1dad9d5024627e3'
         '77287dc835afbb8cc4e9c4aa6b7adb7b')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/0004-fix-gtkdoc.all.patch
  patch -p1 -i ${srcdir}/0005-fix-strtok-conflict.mingw.patch

  autoreconf -fi
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-zlib \
    --enable-shared --disable-static \
    --enable-cxx \
    --enable-nls \
    --disable-rpath \
    --disable-gtk-doc \
    --with-libiconv-prefix=${MINGW_PREFIX} \
    --with-libregex-libs=-lgnurx \
    --disable-guile \
    --disable-libdane \
    gl_cv_double_slash_root=yes
  make
}

check() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make -k check || /bin/true
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install

  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
